#ifndef Chart_Metal_h
#define Chart_Metal_h

#include "YTXTime.h"
#include "IndexConfig.h"

#include <utility>
#include <string>
#include <vector>
#include <map>

namespace ytx
{
    namespace MarketTimeType {
        enum MarketTimeType {
            From0600To0400 = 0,
            From0600To0600,
            From2100To1530,
            From0900To0300,
            From2100To1500,
            From2000To1530,
            From0800To0200,
            From0600To0515,
            From0700To0615,
            From0700To0515,
            From0800To0615,
            From0900To0600,
            From0930To1500,// 股票
            Fromzsj_r,//郑州商品交易所
            Fromzsj_y,//
            Fromdsj_r,//大连商品交易所
            Fromdsj_y,//
            Fromsqj_r,//上海期货交易所
            Fromsqj_y0,//
            Fromsqj_y1,//
            Fromsqj_y2,//20
            Fromzjqj_r0,//中国金融期货交易所
            Fromzjqj_r1,//
            Others = 100
        };
    }

    struct TimeString
    {
	public:
		std::vector<std::string> big;
        std::vector<std::string> middle;
        std::vector<std::string>  small;
        TimeString() {};
        TimeString(const std::vector<std::string> &big, const std::vector<std::string> &middle, const std::vector<std::string> &small) : big(big), middle(middle), small(small) {}
	};

    struct Rect
    {
        int big;
        int middle;
        int small;
        Rect(int big = 0, int middle = 0, int small = 0) : big(big), middle(middle), small(small) {};
    };


	class Metal
    {
	public:
        Metal(std::string name, std::string nickname,
              int dataSum, std::string marketType, std::string id, std::string currentDate, int stepDay,
              TimeString timeString, Rect row, Rect column, YTXTime openTime, YTXTime closeTime, std::vector<std::pair<YTXTime, YTXTime> > restTime, std::map<IndexType::IndexType, IndexConfig> indexConfig, int toFix = 2, bool hasVolume = false, int threshold = 1100, int buffer = 100);
//        virtual ~Metal();
        static std::vector<Metal> initCollection();

        static TimeString createTimeStringByType(int t, std::string openTime = "", std::string endTime = "");

        static TimeString createTimeStringByTimeType(MarketTimeType::MarketTimeType t, std::string openTime = "", std::string endTime = "");
        static MarketTimeType::MarketTimeType timeTypeByTradeTime(std::string tradeTime);
        static TimeString createTimeStringBytradeTime(std::string tradeTime);
        
        static Rect createRowByTimeString(TimeString t);
        
        static Metal createMetal(std::string name, std::string nickname, std::string marketType, std::string id, std::string currentDate, int stepDay, TimeString ts, YTXTime opentime, YTXTime endtime, std::vector<std::pair<YTXTime, YTXTime> > restTime, std::map<IndexType::IndexType, IndexConfig> indexConfig, int toFix, bool hasVolume, Rect column = Rect(10, 6, /*4*/2));
        
        static bool checkData(std::map<std::string, std::string> data);
        
        std::string getCurrentDate();
        int getStepDay();
        std::string getName();

        std::string getNickname();

        int getDataSum();

        std::string getMarketType();

        int getToFix();

        std::string getId();

        int getThreshold();

        int getBuffer();

        YTXTime getOpenTime();

        YTXTime getCloseTime();

        TimeString getTimeString();

        bool isHasVolume();

        Rect getRow();

        Rect getColumn();

        std::vector<std::pair<YTXTime, YTXTime> > getRestTime();

        std::map<IndexType::IndexType, IndexConfig> getIndexConfig();

        static double getAvgAccuracy(std::string id);
    private:
        std::string name;
        std::string nickname;
        int dataSum;
        std::string marketType;
        int toFix;
        std::string id;
        std::string currentDate;
        int stepDay;
        int threshold;
        int buffer;
        YTXTime openTime;
        YTXTime closeTime;
        std::vector<std::pair<YTXTime, YTXTime> > restTime;
        TimeString timeString;
        Rect row;
        Rect column;
        bool hasVolume;
        std::map<IndexType::IndexType, IndexConfig> indexConfig;

	};
}

#endif
